#include <stdlib.h>
#include <stdio.h>
#include "collaboration.h"
#include "MI_client.h"
#include "CORBA_util.h"

MI_client::MI_client(CORBA::ORB_ptr __orb)
{
	orb = __orb;
	
	CosNaming::NamingContext_var inc = auxiliary::resolve_init<CosNaming::NamingContext>(orb, "NameService");
	CosNaming::Name n;
	n.length(2);
	n[0].id = (const char*)"collaboration";
	n[0].kind = (const char*)"";
	n[1].id = (const char*)"DataAccessor";
	n[1].kind = (const char*) "Object";
	
	try{
		ctrl = auxiliary::resolve_name<collaboration::MIDataAccessor>(inc, n);
	}
	catch(const CosNaming::NamingContext::NotFound& e)
	{
		printf("%s\n", e._name());
		exit(1);
	}
}

MI_client::~MI_client()
{
	
}

collaboration::ListOfApplications* MI_client::applications()
{
	return ctrl->applications();
}

collaboration::ListOfUsers* MI_client::users(const char* app)
{
	return ctrl->users_info(app);
}

collaboration::MIDataAccessor_ptr MI_client::get_data_accessor()
{
	return ctrl;
}
